package com.demo.controller;

import com.demo.entity.Student;
import com.demo.entity.Teacher;
import com.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    StudentService studentService;

    @RequestMapping("/userLogin")
    @ResponseBody
    public String forwardMAV(HttpServletRequest request, Integer loginName,String loginPwd){
        if(studentService.Login(loginName,loginPwd).equals("登录成功")){
            HttpSession session = request.getSession();
            session.setAttribute("student",loginName);
            return "登录成功";
        }
        return "账号或者密码错误";
    }
    @RequestMapping("/home")
    public String selectSelf(HttpServletRequest request,String stuId,Model model){
        Student student = (Student)request.getSession().getAttribute("student");
        Integer stuId1 = student.getStuId();
        List<Student> students = studentService.selectSelf(stuId1);
        model.addAttribute("students",students);
        return "showStudentSelf";
    }


}
